package com.zigong.app.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.gridsum.tracker.GridsumWebDissector;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.zigong.app.R;
import com.zigong.app.base.BaseActivity;
import com.zigong.app.beans.AnchorRecommendItem;
import com.zigong.app.beans.FProgramme;
import com.zigong.app.beans.NewsItem;
import com.zigong.app.ui.activities.ReviewActivity;
import com.zigong.app.ui.adapter.AnchorHomePageAdapter;
import com.zigong.app.ui.utils.GlideUtil;
import com.zigong.app.ui.utils.SkipUtil;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/13 0013.
 */

public class AnchorRelateNewsHolder extends BaseAnchorHolder<NewsItem> implements View.OnClickListener {
    @BindView(R.id.item_relate_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_relate_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_relate_date)
    protected CustomFontTextView date;
    @BindView(R.id.item_relate_time)
    protected CustomFontTextView play_length;
    @BindView(R.id.item_reate_img_media)
    protected ImageView news_type;
    @BindView(R.id.item_relate_label)
    protected CustomFontTextView lable;
    @BindView(R.id.tv_anchor_news_more)
    protected CustomFontTextView vMore;
    private NewsItem newsItem;

    public AnchorRelateNewsHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewsItem newsItem) {
        this.newsItem = newsItem;
        title.setText(newsItem.getNewsTitle());
        date.setText(DateUtils.formatDate(DateUtils.getDataDate(newsItem), "MM-dd  HH:mm"));
        lable.setText(newsItem.getLable());
        GlideUtil.loadImgSmall169Def(context, newsItem.getNewsImage(), img);
        if (!TextUtils.isEmpty(newsItem.getNewsMediaLength())) {
            play_length.setVisibility(View.VISIBLE);
            play_length.setText(newsItem.getNewsMediaLength());
        } else {
            play_length.setVisibility(View.GONE);
        }
        if (newsItem.getNewsType() == 2) { //音频
            news_type.setImageResource(R.mipmap.icon_home_voice);
            news_type.setVisibility(View.VISIBLE);
        } else if (newsItem.getNewsType() == 3) {   //视频
            news_type.setImageResource(R.mipmap.icon_home_play);
            news_type.setVisibility(View.VISIBLE);
        } else {
            news_type.setVisibility(View.GONE);
        }
        if (newsItem.isLastItem()) {
            vMore.setVisibility(View.VISIBLE);
        } else {
            vMore.setVisibility(View.GONE);
        }
        vMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (internalClick != null) {
                    internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (newsItem != null) {
            SkipUtil.skipWithNewsItem(context, newsItem, new HashMap<String, String>());
        }
    }

}
